package main

import (
	"fmt"
	"io"
	"os"
	"strings"
)

func ReadFrom(reader io.Reader, num int) ([]byte, error) {
	p := make([]byte, num)
	n, err := reader.Read(p)
	if n > 0 {
		return p[:n], nil
	}
	return p, err
}

func sampleReadFromStdin() {
	fmt.Println("please in put!")

	data, err := ReadFrom(os.Stdin, 10)
	fmt.Println(data, err)
}

func sampleReadFromString() {
	ioString := strings.NewReader("hello world string")
	data, err := ReadFrom(ioString, 50)
	fmt.Println(data, err)
}

func sampleReadFromFile() {
	file, _ := os.Open("io1.go")
	defer file.Close()

	data, err := ReadFrom(file, 10)
	fmt.Println(data, err)
}

func main() {
	//	sampleReadFromString()

	//	sampleReadFromStdin()

	sampleReadFromFile()
}
